<?php
$dbhost = '47.110.131.55';
$dbuser = 'root';
$dbpwd  ='sxy7788123456';
$dbName ='race';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {}


//判断题1分，单选题2分 不定项选择题 3分
$fenshu=0;

$table='u3_c1';
if (isset($_GET['table'])){
    $table=$_GET['table'];
}else{
    exit;
}
echo $table,'....user table';
echo "<br /><br />";

$sql="select openid,id,name from ".$table." where fen is NULL limit 0, 10";
$query=$mysqli->query($sql);
$has=false;
while ($getUser=$query->fetch_assoc()){
    $fen=0;
    $logTable='';
    $c3table='';
    if ($table == 'u3_c1'){
        $logTable='c3_log_c1';
        $c3table='c3_c1';
    }
    if ($table == 'u3_c2'){
        $logTable='c3_log_c2';
        $c3table='c3_c2';
    }
    if ($table == 'u3_c3'){
        $logTable='c3_log_c3';
        $c3table='c3_c3';
    }
    if ($table == 'u3_yc'){
        $logTable='c3_log_yc';
        $c3table='c3_yc';
    }
    if ($table == 'u3_g1'){
        $logTable='c3_log_g1';
        $c3table='c3_g1';
    }
    if ($table == 'u3_g2'){
        $logTable='c3_log_g2';
        $c3table='c3_g2';
    }
    if ($table == 'u3_g3'){
        $logTable='c3_log_g3';
        $c3table='c3_g3';
    }
    if ($table == 'u3_zz'){
        $logTable='c3_log_zz';
        $c3table='c3_zz';
    }
    
    if (empty($logTable)){
        echo 'empty log table';
        exit;
    }
    
    $queryc3=$mysqli->query("select fen from ".$c3table." where openid='".$getUser['openid']."' ");
    if($queryc3->num_rows>0){
        $getC3=$queryc3->fetch_assoc();
        $fen=$getC3['fen'];
        echo $c3table.' table fen : ',$getC3['fen'];
        echo "<br />";
    }
    
    $querylog=$mysqli->query("select fen from ".$logTable." where openid='".$getUser['openid']."' ");
    if($querylog->num_rows>0){
        $getLog=$querylog->fetch_assoc();
        if ($fen < $getLog['fen']){
            $fen=$getLog['fen'];
        }
        echo $logTable.' table fen : ',$getLog['fen'];
        echo "<br />";
    }
    echo "最终分数；&nbsp;&nbsp;&nbsp;&nbsp;",$fen;
    echo "<br /><br />";
    var_dump($getUser);
    echo "<br /><br />";
    $sql="update ".$table." set fen=".$fen." where id='".$getUser['id']."' ";
    echo $sql;
    $mysqli->query($sql);
    $has=true;
    echo "<br />";
    echo '.....................................';
    echo "<br /><br /><br /><br />";
    
}

$mysqli->close();

?>
<?php if (true == $has){ ?>
<script>
window.setTimeout(function(){
	location.reload();
},400);
</script>
<?php } ?>


